package com.csxy.yhj.service.impl;

import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csxy.yhj.api.VodClient;
import com.csxy.yhj.entity.EduVideo;
import com.csxy.yhj.mapper.EduVideoMapper;
import com.csxy.yhj.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Autowired
    private VodClient vodClient;

    @Override
    public void removeVideoByCourseId(String id) {
        //根据课程id查询课程里面所有id
        QueryWrapper<EduVideo> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id",id);
        wrapper.select("video_source_id");
        List<EduVideo> eduVideos = baseMapper.selectList(wrapper);
        List<String> list =new ArrayList<>();
        for(EduVideo eduVideo:eduVideos){
            String sourceId = eduVideo.getVideoSourceId();
            if(!StringUtils.isEmpty(sourceId)){
                list.add(sourceId);
            }
        }
        //根据多个课程id删除课程视频
        QueryWrapper<EduVideo> querWrapper2 = new QueryWrapper<>();
        querWrapper2.eq("course_id",id);
        baseMapper.delete(querWrapper2);

    }
}
